import Vue from 'vue'

import Cookies from 'js-cookie'

import ElementUI from 'element-ui'

import './assets/less/base.scss'
import './assets/less/style.scss'
import './assets/less/scrollbar.css'
import 'font-awesome/css/font-awesome.css'

import 'element-ui/lib/theme-chalk/index.css'

import '@/common/styles/index.scss' // global css
import 'handsontable-pro/dist/handsontable.full.css' // handsontable css
import 'handsontable-pro/languages/zh-CN'
import 'v-org-tree/dist/v-org-tree.css' // 组织树

import animated from 'animate.css'
Vue.use(animated)

import Griddrag from '../static/griddrag/vueGriddrag.min.js'
import '../static/griddrag/vue-griddrag.css'
Vue.use(Griddrag)

import App from './App'
import router from './router'
import store from './store'

import i18n from '@/common/lang' // Internationalization
import '@/common/icons' // icon
import '@/common/utils/permission' // permission control
import '@/common/utils/commonComponent' // commonComponent control

import Layout from '@/views/layout/Layout'

// eventBus 拥有生命周期
import eventBus from '@/common/utils/eventBus'
Vue.use(eventBus)
// 组织树
import OrgTree from 'v-org-tree'
Vue.use(OrgTree)
import Vue2Dnd from 'vue2-dnd'
Vue.use(Vue2Dnd)
import InfiniteScroll from '@/directives/infinite-scroll'
import TableLoadmore from '@/directives/table-loadmore'
Vue.directive('infiniteScroll', InfiniteScroll)
Vue.directive('tableLoadmore', TableLoadmore)

// vue 存储
import Storage from 'vue-ls'
const options = {
    namespace: 'vuejs__', // key prefix
    name: 'ls', // name variable Vue.[ls] or this.[$ls],
    storage: 'local' // storage name session, local, memory
}

Vue.use(Storage, options)

// 表单生成器
import FormMaking from '@/common/utils/formMaking'
Vue.use(FormMaking)
import { Cell, CellGroup } from 'vant'
Vue.use(Cell).use(CellGroup)
import _ from 'lodash'
Vue.prototype._ = _
Vue.prototype.jQueryAPIUrl = 'http://localhost:8080'

Cookies.set('MYEHRFLAG', 'MYEHRFLAG')

// 添加全局注册动态路由方法
Vue.prototype.gotoMyehrPath = function(path, param, title, cache) {
    // console.log(path, param, title, cache)
    if (param) {
        console.log('进param')
        this.$router.push({ path: path, query: param })
    } else {
        console.log('不进param')
        this.$router.push(path)
    }
}

// 每一条业务线对应着一个独立的组件，业务线有各自的 id
const modules = {
    1: null
}
window.EHRApp = {
    Vue,
    store, // 全局store
    registerBiz(id, component) {
        modules[id] = component
    }
}

Vue.use(ElementUI, {
    size: Cookies.get('size') || 'medium', // set element-ui default size
    i18n: (key, value) => i18n.t(key, value)
})

Vue.config.productionTip = false

new Vue({
    el: '#app',
    router,
    store,
    i18n,
    render: h => h(App)
})
